package exam.controller;


import exam.bean.UserInfo;
import exam.common.dto.SysMenuDto;
import exam.utils.Msg;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController extends BaseController{

    @GetMapping("/nav")
    public Msg nav(Principal principal){
        Map<String,Object> queryMap = new HashMap<>();
        queryMap.put("name",principal.getName());
        UserInfo userInfo = userInfoService.selectInfoSingle(queryMap);

        //获取权限信息
        String permStr = groupAndMenuInfoService.getPermissionMenu(userInfo);
        String[]  permStrArray = StringUtils.tokenizeToStringArray(permStr,",");
        //获取导航栏信息
        List<SysMenuDto> navs = groupAndMenuInfoService.getMenuList();

        return Msg.success()
                .add("authority",permStrArray)
                .add("nav",navs);
    }
}
